﻿// ***********************************************************************
// Project			: Micua
// Assembly         : Micua.BLLFactory
// Author           : iceStone
// Created          : 2013-11-18 11:59
//
// Last Modified By : iceStone
// Last Modified On : 2014-01-05 17:28
// ***********************************************************************
// <copyright file="DAO.cs" company="Wedn.Net">
//     Copyright (c) Wedn.Net. All rights reserved.
// </copyright>
// <summary></summary>
// ***********************************************************************
using Micua.BLL;
using Micua.IBLL;
using Micua.Model;
using Micua.RepositoryFactory;
using Micua.Utility.Abstract;

namespace Micua.ServiceFactory
{
    /// <summary>
    /// 业务逻辑层工厂
    /// </summary>
	/// <remarks>
	///  2013-11-18 20:02 Created By iceStone
    ///  2014-01-05 17:28 Modified By iceStone
	/// </remarks>
    public class ServiceFactory : Singleton<ServiceFactory>, IServiceFactory
    {
        private ServiceFactory() { }
        //private readonly string _path = Config.BLLPath;
        //private readonly string _nspace = string.IsNullOrEmpty(Config.BLLNameSpace) ? Config.BLLPath : Config.BLLNameSpace;
        private ICategoryService _category;
        /// <summary>
        /// CategoryService 实例
        /// </summary>
        /// <value>The Category manager.</value>
		public ICategoryService CategoryService
        {
            get
			{
				return _category ?? (_category = new CategoryService());
				//string className = nspace + ".CategoryService";
				//return CreateInstance<ICategoryService>(iCategory, className);
			}
        }

        private ICommentService _comment;
        /// <summary>
        /// CommentService 实例
        /// </summary>
        /// <value>The Comment manager.</value>
		public ICommentService CommentService
        {
            get
			{
				return _comment ?? (_comment = new CommentService());
				//string className = nspace + ".CommentService";
				//return CreateInstance<ICommentService>(iComment, className);
			}
        }

        private ICommentMetaService _commentmeta;
        /// <summary>
        /// CommentMetaService 实例
        /// </summary>
        /// <value>The CommentMeta manager.</value>
		public ICommentMetaService CommentMetaService
        {
            get
			{
				return _commentmeta ?? (_commentmeta = new CommentMetaService());
				//string className = nspace + ".CommentMetaService";
				//return CreateInstance<ICommentMetaService>(iCommentMeta, className);
			}
        }

        private ILinkService _link;
        /// <summary>
        /// LinkService 实例
        /// </summary>
        /// <value>The Link manager.</value>
		public ILinkService LinkService
        {
            get
			{
				return _link ?? (_link = new LinkService());
				//string className = nspace + ".LinkService";
				//return CreateInstance<ILinkService>(iLink, className);
			}
        }

        private IOptionService _option;
        /// <summary>
        /// OptionService 实例
        /// </summary>
        /// <value>The Option manager.</value>
		public IOptionService OptionService
        {
            get
			{
				return _option ?? (_option = new OptionService());
				//string className = nspace + ".OptionService";
				//return CreateInstance<IOptionService>(iOption, className);
			}
        }

        private IPostService _post;
        /// <summary>
        /// PostService 实例
        /// </summary>
        /// <value>The Post manager.</value>
		public IPostService PostService
        {
            get
			{
				return _post ?? (_post = new PostService());
				//string className = nspace + ".PostService";
				//return CreateInstance<IPostService>(iPost, className);
			}
        }

        private IPostMetaService _postmeta;
        /// <summary>
        /// PostMetaService 实例
        /// </summary>
        /// <value>The PostMeta manager.</value>
		public IPostMetaService PostMetaService
        {
            get
			{
				return _postmeta ?? (_postmeta = new PostMetaService());
				//string className = nspace + ".PostMetaService";
				//return CreateInstance<IPostMetaService>(iPostMeta, className);
			}
        }

        private ITagService _tag;
        /// <summary>
        /// TagService 实例
        /// </summary>
        /// <value>The Tag manager.</value>
		public ITagService TagService
        {
            get
			{
				return _tag ?? (_tag = new TagService());
				//string className = nspace + ".TagService";
				//return CreateInstance<ITagService>(iTag, className);
			}
        }

        private IUserService _user;
        /// <summary>
        /// UserService 实例
        /// </summary>
        /// <value>The User manager.</value>
		public IUserService UserService
        {
            get
			{
				return _user ?? (_user = new UserService());
				//string className = nspace + ".UserService";
				//return CreateInstance<IUserService>(iUser, className);
			}
        }

        private IUserMetaService _usermeta;
        /// <summary>
        /// UserMetaService 实例
        /// </summary>
        /// <value>The UserMeta manager.</value>
		public IUserMetaService UserMetaService
        {
            get
			{
				return _usermeta ?? (_usermeta = new UserMetaService());
				//string className = nspace + ".UserMetaService";
				//return CreateInstance<IUserMetaService>(iUserMeta, className);
			}
        }

        /// <summary>
        /// 保存数据库的改变状态
        /// </summary>
		/// <remarks>
		///  2013-11-18 20:02 Created By iceStone
		///  2014-01-05 17:28 Modified By iceStone
		/// </remarks>
        /// <returns>受影响行数</returns>
        public int DbSaveChanges()
        {
            Statistics.Instance.QueryCount++;
            return DbSession.Instance.SaveChanges();
        }

        public void Dispose()
        {
            DbSession.Instance.Dispose();
        }
		
        //private static ServiceFactory _instance;
        ///// <summary>
        ///// ServiceFactory实例；
        ///// </summary>
        //public static ServiceFactory Instance
        //{
        //    get
        //    {
        //        if (_instance != null) return _instance;
        //        lock ("BLLFactoryLockHelper") { _instance = _instance ?? new ServiceFactory(); }
        //        return _instance;
        //    }
        //}
    }
} 
